package com.dhsc.service.impl.wskh;

import java.text.DecimalFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.ywzx.wskh.WskhShtjVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.wskh.IWskhShtjDao;
import com.dhsc.service.wskh.IWskhShtjService;
import com.dhsc.util.CommonUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class WskhShtjServiceImpl implements IWskhShtjService{

	@Autowired
	private IWskhShtjDao twskhshtjDao;

	@Override
	public LayuiTableVo queryWskhShtjByAll(WskhShtjVo y) {
		LayuiTableVo obj = new LayuiTableVo();
		try{
			PageMethod.startPage(y.getPage(),y.getLimit());
			List<WskhShtjVo> list = twskhshtjDao.queryWskhShtjByAll(y);
			PageInfo<WskhShtjVo> pageInfo = new PageInfo<>(list);
	
			int shzsl=0;
			if(CommonUtil.isNotEmptyList(list))
			{
				DecimalFormat df = new DecimalFormat("0.00");
				for(int i = 0;i < list.size();i ++)
				{
					shzsl=shzsl+list.get(i).getShsl();
				}
				if(shzsl!=0){
					for(int i = 0;i < list.size();i ++)
					{
						double shsl=Double.parseDouble(list.get(i).getShsl()+"");
						String shzb=df.format(shsl/shzsl*100);
					
						list.get(i).setShzb(shzb);
					}
					
					WskhShtjVo hj = new WskhShtjVo();
					hj.setTruename("合计");
					hj.setShsl(shzsl);
					hj.setShzb("100.00");
					list.add(hj);
				}
			}

			obj.setData(list);
			obj.setMsg("");
			obj.setCount(pageInfo.getTotal());
			obj.setCode(0);
		}catch(Exception e){
			log.error("查询网上开户审核统计出错", e);
			throw new MyException("查询网上开户审核统计出错",e);
		}
		return obj;
	}
}